/**************************************************************************************
 *
 * @(#) WebMvcConfigurer.java
 * @Package com.jgdt.jgdtkasannong_university_gene_backend.config.mvc
 **************************************************************************************/
package com.jgdt.jgdtkasannong_university_gene_backend.config.mvc;

import com.jgdt.jgdtkasannong_university_gene_backend.common.Sysconstant;
import com.jgdt.jgdtkasannong_university_gene_backend.config.enums.FilePatternsEnums;
import com.jgdt.jgdtkasannong_university_gene_backend.config.enums.SysValueSetEnums;
import com.jgdt.jgdtkasannong_university_gene_backend.config.enums.template.TemplateCodeEnums;
import com.jgdt.jgdtkasannong_university_gene_backend.service.content.MediaService;
import com.jgdt.jgdtkasannong_university_gene_backend.service.sys.SysValueSetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * @description: 服务器资源访问映射
 * @author: huangAn
 * @createDate: 2025/04/29
 */
@Configuration
@Slf4j
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private SysValueSetService sysValueSetService;
    @Autowired
    private MediaService mediaService;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String tempImgCataloguePrefixHead=sysValueSetService.queryPriorityValueByCode(SysValueSetEnums.TEMP_IMG_CATALOGUE_PREFIX_HEAD.getCode());
        String tempImgCatalogue=sysValueSetService.queryPriorityValueByCode(SysValueSetEnums.TEMP_IMG_CATALOGUE.getCode());
        String imgUrl=tempImgCataloguePrefixHead+tempImgCatalogue;
        String pathPatterns="/"+SysValueSetEnums.FRONT_VISIT_IMG_PREFIX.getValue()+"/**";
//        String filePatterns="file:/root/gene/dumps/"; // dev 环境
//        String filePatterns="file:/";   //测试 本地环境
        String filePatterns=null;
//        String code=FilePatternsEnums.getEnumsByIsEnable().getCode();
        String code= mediaService.getFilePatternsCode();
        if(FilePatternsEnums.WIDOS.getCode().equals(code)){
              filePatterns= FilePatternsEnums.getValuesByCode(FilePatternsEnums.WIDOS.getCode());
        }else if(FilePatternsEnums.LINX.getCode().equals(code)){
              filePatterns= FilePatternsEnums.getValuesByCode(FilePatternsEnums.LINX.getCode());
        }else{
            log.warn("getAfterLastSlash warn:配置文件FilePatternsEnums.java有问题");
        }

        String researchPatterns=filePatterns+imgUrl+ TemplateCodeEnums.RESEARCHTEAM.getImportUrl()+"/";
        String achievementsPatterns=filePatterns+imgUrl+ TemplateCodeEnums.RESEARCH_ACHIEVEMENTS.getImportUrl()+"/";
        String placePatterns=filePatterns+imgUrl+ TemplateCodeEnums.PLACE_BASE.getImportUrl()+"/";
        String leanPatterns=filePatterns+imgUrl+ TemplateCodeEnums.LEAN_MEAT_BASE.getImportUrl()+"/";
        String blackPatterns=filePatterns+imgUrl+ TemplateCodeEnums.BLACK_PIG_BASE.getImportUrl()+"/";
        String innovatePatterns=filePatterns+imgUrl+ TemplateCodeEnums.INNOVATE_BASE.getImportUrl()+"/";
        String hallPatterns=filePatterns+imgUrl+ Sysconstant.HALL_IMG_IMPORTURL+"/";
        //视频截屏 默认图片目录
        String videoPatterns=filePatterns+imgUrl+Sysconstant.VIDEO_IMG_IMPORTURL+"/";
        log.info("pathPatterns:"+pathPatterns);
        log.info("researchPatterns:"+researchPatterns);
        log.info("achievementsPatterns:"+achievementsPatterns);
        log.info("placePatterns:"+placePatterns);
        log.info("leanPatterns:"+leanPatterns);
        log.info("blackPatterns:"+blackPatterns);
        log.info("innovatePatterns:"+innovatePatterns);
        log.info("hallPatterns:"+hallPatterns);
        registry.addResourceHandler(pathPatterns)
                .addResourceLocations(researchPatterns,achievementsPatterns,
                 placePatterns,leanPatterns,blackPatterns,innovatePatterns,hallPatterns,videoPatterns);
    }
}



